package com.example.animation_1;

import java.io.InputStream;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



import android.R.integer;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.res.Resources;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;


public class MainActivity extends Activity {

	ImageView img;
	Handler hand =  new Handler();
	public static final int  GET_DATA_INTERVAL=6000;
	int arrimg[] = {R.drawable.banner_fptplay,R.drawable.banner_vnexpress};
	int index=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        img= (ImageView) findViewById(R.id.imgPicture);
        img.postDelayed(run, GET_DATA_INTERVAL);
        
    }
    
    Runnable run =  new Runnable() {
		
		@SuppressWarnings("deprecation")
		@Override
		public void run() {
			// TODO Auto-generated method stub
			final boolean isDo=true;
			img.setBackgroundDrawable(getResources().getDrawable(arrimg[index++]));
			final Animation  anim =  AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation);
			final Animation animOut= AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation_out);
			img.startAnimation(anim);
			
			
				Handler handlerOut = new Handler();
				handlerOut.postDelayed(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						img.clearAnimation();
						img.startAnimation(animOut);
						
						
						
					}
				}, 5500);
			
			
			
            if (index == arrimg.length)
                index = 0;
            hand.postDelayed(run, GET_DATA_INTERVAL);
		}
	};
	
	Runnable runOut= new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			Animation animOut= AnimationUtils.loadAnimation(MainActivity.this, R.anim.animation_out);
			img.startAnimation(animOut);
			hand.postDelayed(run, 4000);
		}
	};

  

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    public RotateAnimation ain(){
    	RotateAnimation anim = new RotateAnimation(0f, 360f, 50f, 50f);
    	anim.setInterpolator(new LinearInterpolator());
    	anim.setRepeatCount(Animation.INFINITE);
    	
    	
    	anim.setDuration(5000);
    	return anim;
    }
  
    
    
}
    
    
